package com.hkj.genealogy.genealogydemo.service;

import com.hkj.genealogy.genealogydemo.entity.User;
import com.hkj.genealogy.genealogydemo.mapper.GenealogyMapper;
import com.hkj.genealogy.genealogydemo.mapper.UserMapper;
import com.hkj.genealogy.genealogydemo.service.api.UserService;
import com.hkj.genealogy.genealogydemo.util.IdUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: genealogydemo
 * @description: UserService实现类
 * @author: Hekejian
 * @time: 2020-07-05 00:02
 **/
@Service
public class UserServiceImp implements UserService {
    @Resource
    UserMapper userMapper;
    @Resource
    GenealogyMapper genealogyMapper;
    @Override
    public boolean registerNewUser(User user,Long id) throws Exception {
        try {
            if(userMapper.insertUser(user)==1&&genealogyMapper.insertGenealogy(id)==1&&genealogyMapper.createRelationUserGenealogy(user.getId(),id)==1) return true;
        }
        catch (Exception e){
            throw new Exception();
        }
        return false;
    }

    @Override
    public User getUserInfo(String account) {
        return userMapper.getUserInfo(account);
    }

    @Override
    public Long gerUserFid(Long id) {
        return userMapper.gerUserFid(id);
    }
}
